/**
 *  二维码 控制器
 *  
 *  @date 2014-11-19
 */
package com.chnbst.bstyun.controller.user;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.chnbst.bstyun.model.pojo.ProductDownload;
import com.chnbst.bstyun.service.ProductDownloadService;


@Controller
public class QRCodeController {
	@Autowired
	private ProductDownloadService productDownloadService;

	/**
	 * http://xxx.com/qrcode
	 * @return 产品下载地址
	 * @throws Exception
	 */
	@RequestMapping(value="/qrcode",method=RequestMethod.GET)
	public ModelAndView AndroidQRCode(HttpServletRequest request)throws Exception{
		String productId = request.getParameter("productId");
		String downloadWayId = request.getParameter("downloadWayId");
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("productId", productId);
		map.put("downloadWayId", downloadWayId);
		
		ProductDownload pd = productDownloadService.selectProductDownloadByProductIdAndDownloadWayId(map);
		
		System.out.println(productId+"--"+downloadWayId);
		return new ModelAndView("redirect:"+pd.getDownloadUrl());
	}
	
	
	/**
	 * 云随洽安卓版下载
	 * @return 安卓版二维码
	 * @throws Exception
	 */
	@RequestMapping(value="/http://www.chnbst.com/u/cms/www/201410/16095807wzaf.apk",method=RequestMethod.GET)
	public ModelAndView AndroidQRCode()throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("productId", 3);
		map.put("downloadWayId", 1);
		ProductDownload pd = productDownloadService.selectProductDownloadByProductIdAndDownloadWayId(map);
		return new ModelAndView("redirect:"+pd.getDownloadUrl());
	}
	
	/**
	 * 云随洽IOS版下载
	 * @return IOS版二维码
	 * @throws Exception
	 */
	@RequestMapping(value="/http://www.chnbst.com/u/cms/www/201410/17175137m16q.ipa",method=RequestMethod.GET)
	public ModelAndView IOSQRCode()throws Exception{
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("productId", 3);
		map.put("downloadWayId", 2);
		ProductDownload pd = productDownloadService.selectProductDownloadByProductIdAndDownloadWayId(map);
		return new ModelAndView("redirect:"+pd.getDownloadUrl());
	}
}
